package projet;

import java.lang.String;
import java.util.*;

import donnees.ressources.RAM;
import donnees.ressources.Ressource;

/**
 *  This class uses a native C method to periodically collect the memory load.
 *  It provides the virtual and physical utilisation of memory. 
 *  It extends thread so it can run into a separate thread.
 *
 */

public class MemLoad extends Thread{
    /** time beetween two watches */
    private long watchPeriod;
    private RAM ram;
    /**
     *  Constructs a memLoad object with a link to the specified Architecture 
     *  object.
     *
     *  @param watchPeriod - time beetween two watches
     */
    public MemLoad( long watchPeriod, RAM ram){
	this.watchPeriod = watchPeriod;
	this.ram = ram;
    }


    /**
     *  Constructs a new Resource object containing the percentage of used 
     *  swap and physical memory
     *  This object is then added to the stateInformation 
     *  hashtable in the archi field.
     *
     *  @param phys_total_mem - total physical memory
     *  @param phys_used_mem - used physical memory
     *  @param sw_total_mem - total swap memory
     *  @param sw_used_mem - used swap memory
     */
    public void setValues(float phys_total_mem, float phys_used_mem, float sw_total_mem, float sw_used_mem) {	
    
	/**** ici vous mettez le remplissage de vos structures ****/
	/*System.out.println(
	"total physical memory (Mo):"+ phys_total_mem+
	", physical memory used (pourcent):"+phys_used_mem+
	", total swap memory (Mo):"+sw_total_mem+
	", swap memory used (pourcent):"+sw_used_mem);*/
	ram.setValeur(phys_used_mem);
    }
    
    /**
     *  Native method associated with the C function which collects state 
     *  information.
     */
   public native void StatMem(int watchPeriod);

    /**
     *  Launches a new cpuLoad object in a separate thread
     */
    public void run(){
    	int tempo = (int)watchPeriod/1000;
    	this.StatMem(tempo);
    	while(true){ } 
    	} 
    
    static {
	System.loadLibrary("stat");
    }
}
